-- hp_to_attack_frighten
-- created by zhuangsl
-- 生命高于一定百分比时，攻击概率击晕敌人

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    trigger = function(who, prop, arg)
        local target = arg;

        -- 生命高于指定百分比时候才会触发
        local rate = math.modf(1000 * who:queryAttrib("hp") / who:queryAttrib("max_hp"));
        local valve = tonumber(prop[2])
        if (rate < valve) then
            return;
        end

        -- 概率触发
        local rand = DungeonM.getRandSeed("hp_to_attack_frighten") % 1000;
        if (rand > prop[3]) then
            return;
        end

        local condition = {
            ["end_round"] = CombatM.getRound() + prop[4],
        };

        -- 附加状态
        CombatStatusM.applyStatus(target, "cutting", condition);

        local prop = PropM.combine(ME.user, "hunting", 52);
        if prop[3] > 0 then
            -- 触发特技发动事件
            EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
        end

        return true;
    end,

    record = function(target, prop, path)
        return false;
    end
};
